package com.crm.jdy.controller.drp;

import com.crm.jdy.common.dto.ProjectInfoDto;
import com.crm.jdy.common.dto.WInInfoDto;
import com.crm.jdy.common.pojo.ProjectInfo;
import com.crm.jdy.common.pojo.WInInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.drp.WInInfoService;
import com.crm.jdy.service.project.ProjectInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 入库列表信息API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年4月12日
*
*/
@Api(tags = "wInInfo", description ="入库列表信息")
@RestController
@RequestMapping("/wInInfo")
public class WInInfoController{

    @Reference(version = "${service.version}", check = false)
    WInInfoService wInInfoService;

    @RateLimit()
    @ApiOperation("入库列表信息")
    @PostMapping("/seleteWInInfo")
    public ResultVo seleteWInInfo(@RequestBody WInInfoDto projectInfoDto){
        PageInfo<WInInfo> list = wInInfoService.seleteWInInfo(projectInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新入库列表信息")
    @PostMapping("/updateWInInfo")
    public ResultVo updateWInInfo(@ApiParam(value = "projectInfo", required = true)
                                      @Validated @RequestBody WInInfo projectInfo){
        boolean index = wInInfoService.updateWInInfo(projectInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加入库列表信息")
    @PostMapping("/addWInInfo")
    public ResultVo addWInInfo(@ApiParam(name = "projectInfo", required = false)
                                   @Validated @RequestBody WInInfo projectInfo){
        boolean list  = wInInfoService.addWInInfo(projectInfo);
        if(list){
            return ResultVo.success("添加成功");
        }
        return ResultVo.failed("添加失败，数据已存在");
    }

    @RateLimit()
    @ApiOperation("删除入库列表信息")
    @DeleteMapping("deleteWInInfo/{inId}")
    public ResultVo deleteWInInfo(@NotNull @ApiParam(name = "inId", value = "inId", required = true) @PathVariable String inId){
        boolean b = wInInfoService.removeWInInfo(inId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }


}